import Mock from 'mockjs'

const List = []
const count = 100

for (let i = 0; i < count; i++) {
  List.push(
    Mock.mock({
      timestamp: +Mock.Random.date('T'),
      tagId: '@increment',
      userName: '@first',
      userId: '@increment',
      'userPost|1': ['storage', 'employee', 'admin']
      // userPost: function() {
      //   let list = ['工作区', '办公室', '会议室', '仓库']
      //   let result = []
      //   for (let i = 0; i <= Math.floor(Math.random() * list.length); i++) {
      //     let index = Math.floor(Math.random() * list.length)
      //     result.push(list[index])
      //     list.splice(index, 1)
      //   }
      //   return result
      // }
    })
  )
}

export default [
  {
    url: '/setting/tag',
    type: 'get',
    response: config => {
      console.log(config)
      const {
        page = 1,
        limit = 20,
        userName
        // sort
      } = config.query

      let mockList = List.filter(item => {
        // if (importance && item.importance !== +importance) return false
        // if (type && item.type !== type) return false
        if (userName && item.userName.indexOf(userName) < 0) return false
        return true
      })

      // let mockList = List

      // if (sort === '-id') {
      //   mockList = mockList.reverse()
      // }

      const pageList = mockList.filter(
        (item, index) => index < limit * page && index >= limit * (page - 1)
      )

      return {
        code: 0,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },

  {
    url: '/getPostType',
    type: 'get',
    response: config => {
      console.log(config)

      return [
        { userPost: 'storage' },
        { userPost: 'admin' },
        { userPost: 'employee' }
      ]
    }
  },

  {
    url: '/tag/createTag',
    type: 'get',
    response: config => {
      console.log(config)

      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  {
    url: '/tag/updateTag',
    type: 'get',
    response: config => {
      console.log(config)
      return {
        code: 20000,
        data: 'success'
      }
    }
  },
  {
    url: '/setting/deleteTag',
    type: 'post',
    response: config => {
      console.log(config)

      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]
